package cn.iocoder.devlop.module.annual.report.record.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.record.controller.vo.ReportRecordBaseVO;
import cn.iocoder.devlop.module.annual.report.record.convert.ReportRecordConvert;
import cn.iocoder.devlop.module.annual.report.record.dal.dataobject.ReportRecordDO;
import cn.iocoder.devlop.module.annual.report.record.service.ReportRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 年报记录")
@RestController
@RequestMapping("/annual/report/record")
@Validated
@RequiredArgsConstructor
public class AppReportRecordController {

    private final ReportRecordService reportRecordService;

    @GetMapping
    @Operation(summary = "获取年报记录信息")
    public CommonResult<ReportRecordBaseVO> getRecord(ReportRecordBaseVO baseVO){
        ReportRecordDO reportRecordDO = reportRecordService.getRecord(baseVO);
        return success(ReportRecordConvert.INSTANCE.convert(reportRecordDO));
    }

    @PostMapping
    @Operation(summary = "保存年报记录信息")
    public CommonResult<Boolean> saveRecord(@RequestBody ReportRecordBaseVO baseVO){
        reportRecordService.saveRecord(baseVO);
        return success(true);
    }

}
